import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

public class Consumer_Listener implements MessageListener {
    private int i = 0;
    private int n;
    private int epoch = 0;

    public void equaln(int n){
        this.n = n;
    }

    public double[] average = new double[1];
//    public double average;
    public double[] me = new double[1];
    public double[] max = new double[1];
    public double[] min = new double[1];
    private int time = 1;



    @Override
    public void onMessage(Message message) {
        double[] msglist = new double[n];

        try {
//            System.out.println(n);
            if (i < n) {
                msglist[i] = (double) (((ObjectMessage) message).getObject());
//                System.out.println("进入第一个if条件");
//                System.out.println("接受到一个随机数为" + msglist[i]);
                
//                JFrame frame = new JFrame("动态随机数折线图");
//                RealTimeChart realTimeChart = new RealTimeChart("随机数折线图", "随机数", "数值");
                ASyncConsumer.realTimeChart.getrandom_number(msglist[i]);
//                frame.getContentPane().add(realTimeChart, new BorderLayout().CENTER);
//                frame.pack();
//                frame.setVisible(true);
//                (new Thread(realTimeChart)).start();
//                frame.addWindowListener(new WindowAdapter() {
//                    @Override
//                    public void windowClosing(WindowEvent windowevent) {
//                        System.exit(0);
//                    }
//                });
            }
            if (i == n) {
                average[0] = (double) (((ObjectMessage) message).getObject());
                System.out.println("average: "+average[0]);
            }
            if (i == n + 1) {
                me[0] = (double) (((ObjectMessage) message).getObject());
                System.out.println("me: "+me[0]);
            }
            if (i == n + 2) {
                max[0] = (double) (((ObjectMessage) message).getObject());
                System.out.println("max: "+max[0]);
            }
            if (i == n + 3) {
                min[0] = (double) (((ObjectMessage) message).getObject());
                epoch++;
                System.out.println("min: "+min[0]);
                System.out.println("以上为第" + epoch + "次分析数据");
                i = 0;
            }

//						System.out.println(average[0]);
//						System.out.println(me[0]);
//						System.out.println(max[0]);
//						System.out.println(min[0]);
//            System.out.println(i);
            i++;
        } catch (JMSException e) {
            e.printStackTrace();
        }

//        System.out.println("正在获取下一批数据结果，请稍等……");
    }
}